package com.aicheyoudao.utils;

import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiNearbySearchOption;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;

public class SearchUtils {

	private searchResListener listener;
	private static SearchUtils instance;

	public static SearchUtils getSearchUtils() {
		if (instance == null) {
			instance = new SearchUtils();
		}
		return instance;
	}

	public void PoiNearSearch(LatLng latLng, String searchKey) {
		// 初始化搜索模块，注册搜索事件监听
		PoiSearch mPoiSearch = PoiSearch.newInstance();
		mPoiSearch.setOnGetPoiSearchResultListener(new resListener());
		// mPoiSearch.searchInCity((new PoiCitySearchOption()).city(cityName)
		// .keyword(searchKey));
		// 根据中心点、半径与检索词发起周边检索.
		// 参数列表：关键词、中心点地理坐标、半径，单位:米

		mPoiSearch.searchNearby(new PoiNearbySearchOption().location(latLng).keyword(searchKey).radius(10000).pageCapacity(50));
		// 显示等待框

	}

	class resListener implements OnGetPoiSearchResultListener {

		@Override
		public void onGetPoiDetailResult(PoiDetailResult arg0) {

		}

		@Override
		public void onGetPoiResult(PoiResult res) {
			listener.searchSucess(res);
		}

	}

	public void setsearchResListener(searchResListener lis) {

		this.listener = lis;
	}

	public interface searchResListener {
		public void searchSucess(PoiResult res);
	}
}
